home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archivers / XpkDisk / prefswindow.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  8KB  |  259 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Olaf 'Rhialto' Seibert
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include "prefswindow.h"
  24. extern void *SysBase;
  25. extern void *GfxBase;
  26. struct Screen          *Scr = NULL;
  27. UBYTE              *PubScreenName = NULL;
  28. APTR               VisualInfo = NULL;
  29. struct Window          *PrefsWnd = NULL;
  30. struct Gadget          *PrefsGList = NULL;
  31. struct Menu          *PrefsMenus = NULL;
  32. UWORD               PrefsZoom[4];
  33. struct Gadget          *PrefsGadgets[10];
  34. UWORD               PrefsLeft = 55;
  35. UWORD               PrefsTop = 18;
  36. UWORD               PrefsWidth = 349;
  37. UWORD               PrefsHeight = 141;
  38. UBYTE              *PrefsWdt = (UBYTE *)"xpkdisk.device Prefs";
  39. struct TextAttr       *Font, Attr;
  40. UWORD               FontX, FontY;
  41. UWORD               OffX, OffY;
  42.  
  43. struct NewMenu PrefsNewMenu[] = {
  44.     NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
  45.     NM_ITEM, (STRPTR)"About", NULL, 0, 0L, NULL,
  46.     NM_ITEM, (STRPTR)"Open...", (STRPTR)"O", 0, 0L, NULL,
  47.     NM_ITEM, (STRPTR)"Save", (STRPTR)"S", 0, 0L, NULL,
  48.     NM_ITEM, (STRPTR)"Save As...", (STRPTR)"A", 0, 0L, NULL,
  49.     NM_ITEM, (STRPTR)"Use", (STRPTR)"U", 0, 0L, NULL,
  50.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  51.     NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, NULL,
  52.     NM_TITLE, (STRPTR)"Edit", NULL, 0, NULL, NULL,
  53.     NM_ITEM, (STRPTR)"Reset To Defaults", (STRPTR)"D", 0, 0L, NULL,
  54.     NM_ITEM, (STRPTR)"Last Saved", (STRPTR)"L", 0, 0L, NULL,
  55.     NM_ITEM, (STRPTR)"Restore", (STRPTR)"R", 0, 0L, NULL,
  56.     NM_END, NULL, NULL, 0, 0L, NULL };
  57.  
  58. UWORD PrefsGTypes[] = {
  59.     SLIDER_KIND,
  60.     SLIDER_KIND,
  61.     CHECKBOX_KIND,
  62.     CHECKBOX_KIND,
  63.     CHECKBOX_KIND,
  64.     SLIDER_KIND,
  65.     STRING_KIND,
  66.     BUTTON_KIND,
  67.     BUTTON_KIND,
  68.     BUTTON_KIND
  69. };
  70.  
  71. struct NewGadget PrefsNGad[] = {
  72.     95, 103, 158, 11, (UBYTE *)"Unit", NULL, GD_UNIT, PLACETEXT_LEFT, NULL, NULL,
  73.     110, 82, 158, 11, (UBYTE *)"Cache size", NULL, GD_MAXCACHE, PLACETEXT_LEFT, NULL, NULL,
  74.     242, 52, 26, 11, (UBYTE *)"CMD_UPDATE required", NULL, GD_CMDUPDATE, PLACETEXT_LEFT, NULL, NULL,
  75.     242, 22, 26, 11, (UBYTE *)"Timeout required", NULL, GD_DELAY, PLACETEXT_LEFT, NULL, NULL,
  76.     242, 67, 26, 11, (UBYTE *)"Safe write", NULL, GD_SAFE, PLACETEXT_LEFT, NULL, NULL,
  77.     110, 37, 158, 11, (UBYTE *)"Time", NULL, GD_TIME, PLACETEXT_LEFT, NULL, NULL,
  78.     171, 6, 97, 12, (UBYTE *)"Compression", NULL, GD_METHOD, PLACETEXT_LEFT, NULL, NULL,
  79.     14, 120, 95, 16, (UBYTE *)"Save", NULL, GD_SAVE, PLACETEXT_IN, NULL, NULL,
  80.     127, 120, 95, 16, (UBYTE *)"Use", NULL, GD_USE, PLACETEXT_IN, NULL, NULL,
  81.     241, 120, 95, 16, (UBYTE *)"Quit", NULL, GD_QUIT, PLACETEXT_IN, NULL, NULL
  82. };
  83.  
  84. ULONG PrefsGTags[] = {
  85.     (GTSL_Max), 7, (GTSL_MaxLevelLen), 3, (GTSL_LevelFormat), (ULONG)"%ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_RelVerify), TRUE, (TAG_DONE),
  86.     (GTSL_Max), 64, (GTSL_Level), 8, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%2ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_RelVerify), TRUE, (TAG_DONE),
  87.     (GTCB_Checked), TRUE, (TAG_DONE),
  88.     (GTCB_Checked), TRUE, (TAG_DONE),
  89.     (TAG_DONE),
  90.     (GTSL_Max), 300, (GTSL_Level), 5, (GTSL_MaxLevelLen), 6, (GTSL_LevelFormat), (ULONG)"%3ld s", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_RelVerify), TRUE, (TAG_DONE),
  91.     (GA_TabCycle), FALSE, (GTST_String), (ULONG)"BLZW.100", (GTST_MaxChars), 8, (STRINGA_Justification), (GACT_STRINGCENTER), (TAG_DONE),
  92.     (TAG_DONE),
  93.     (TAG_DONE),
  94.     (TAG_DONE)
  95. };
  96.  
  97. static UWORD ComputeX( UWORD value )
  98. {
  99.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  100. }
  101.  
  102. static UWORD ComputeY( UWORD value )
  103. {
  104.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  105. }
  106.  
  107. static void ComputeFont( UWORD width, UWORD height )
  108. {
  109.     Font = &Attr;
  110.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  111.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  112.     FontX = Scr->RastPort.Font->tf_XSize;
  113.  
  114.     OffX = Scr->WBorLeft;
  115.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  116.  
  117.     if ( width && height ) {
  118.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  119.             goto UseTopaz;
  120.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  121.             goto UseTopaz;
  122.     }
  123.     return;
  124.  
  125. UseTopaz:
  126.     Font->ta_Name = (STRPTR)"topaz.font";
  127.     FontX = FontY = Font->ta_YSize = 8;
  128. }
  129.  
  130. int SetupScreen( void )
  131. {
  132.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  133.         return( 1L );
  134.  
  135.     ComputeFont( 0, 0 );
  136.  
  137.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  138.         return( 2L );
  139.  
  140.     return( 0L );
  141. }
  142.  
  143. void CloseDownScreen( void )
  144. {
  145.     if ( VisualInfo ) {
  146.         FreeVisualInfo( VisualInfo );
  147.         VisualInfo = NULL;
  148.     }
  149.  
  150.     if ( Scr        ) {
  151.         UnlockPubScreen( NULL, Scr );
  152.         Scr = NULL;
  153.     }
  154. }
  155.  
  156. void PrefsRender( void )
  157. {
  158.     ComputeFont( PrefsWidth, PrefsHeight );
  159.  
  160.     DrawBevelBox( PrefsWnd->RPort, OffX + ComputeX( 14 ),
  161.                     OffY + ComputeY( 3 ),
  162.                     ComputeX( 322 ),
  163.                     ComputeY( 95 ),
  164.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  165. }
  166.  
  167. int OpenPrefsWindow( void )
  168. {
  169.     struct NewGadget    ng;
  170.     struct Gadget    *g;
  171.     UWORD        lc, tc;
  172.     UWORD        wleft = PrefsLeft, wtop = PrefsTop, ww, wh;
  173.  
  174.     ComputeFont( PrefsWidth, PrefsHeight );
  175.  
  176.     ww = ComputeX( PrefsWidth );
  177.     wh = ComputeY( PrefsHeight );
  178.  
  179.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  180.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  181.  
  182.     if ( ! ( g = CreateContext( &PrefsGList )))
  183.         return( 1L );
  184.  
  185.     for( lc = 0, tc = 0; lc < Prefs_CNT; lc++ ) {
  186.  
  187.         CopyMem((char * )&PrefsNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  188.  
  189.         ng.ng_VisualInfo = VisualInfo;
  190.         ng.ng_TextAttr     = Font;
  191.         ng.ng_LeftEdge     = OffX + ComputeX( ng.ng_LeftEdge );
  192.         ng.ng_TopEdge     = OffY + ComputeY( ng.ng_TopEdge );
  193.         ng.ng_Width     = ComputeX( ng.ng_Width );
  194.         ng.ng_Height     = ComputeY( ng.ng_Height);
  195.  
  196.         PrefsGadgets[ lc ] = g = CreateGadgetA((ULONG)PrefsGTypes[ lc ], g, &ng, ( struct TagItem * )&PrefsGTags[ tc ] );
  197.  
  198.         while( PrefsGTags[ tc ] ) tc += 2;
  199.         tc++;
  200.  
  201.         if ( NOT g )
  202.             return( 2L );
  203.     }
  204.  
  205.     if ( ! ( PrefsMenus = CreateMenus( PrefsNewMenu, GTMN_FrontPen, 0L, TAG_DONE )))
  206.         return( 3L );
  207.  
  208.     LayoutMenus( PrefsMenus, VisualInfo, TAG_DONE );
  209.  
  210.     PrefsZoom[0] = PrefsLeft;
  211.     PrefsZoom[1] = PrefsTop;
  212.     if ( PrefsWdt )
  213.         PrefsZoom[2] = TextLength( &Scr->RastPort, (UBYTE *)PrefsWdt, strlen((char *)PrefsWdt )) + 80;
  214.     else
  215.         PrefsZoom[2]  = 80L;
  216.         PrefsZoom[3] = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  217.  
  218.     if ( ! ( PrefsWnd = OpenWindowTags( NULL,
  219.                 WA_Left,    wleft,
  220.                 WA_Top,     wtop,
  221.                 WA_Width,    ww + OffX + Scr->WBorRight,
  222.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  223.                 WA_IDCMP,    SLIDERIDCMP|CHECKBOXIDCMP|STRINGIDCMP|BUTTONIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
  224.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_SIMPLE_REFRESH,
  225.                 WA_Gadgets,    PrefsGList,
  226.                 WA_Title,    PrefsWdt,
  227.                 WA_ScreenTitle, "xpkdisk.device Prefs",
  228.                 WA_PubScreen,    Scr,
  229.                 WA_Zoom,    PrefsZoom,
  230.                 TAG_DONE )))
  231.     return( 4L );
  232.  
  233.     SetMenuStrip( PrefsWnd, PrefsMenus );
  234.     GT_RefreshWindow( PrefsWnd, NULL );
  235.  
  236.     PrefsRender();
  237.  
  238.     return( 0L );
  239. }
  240.  
  241. void ClosePrefsWindow( void )
  242. {
  243.     if ( PrefsMenus      ) {
  244.         ClearMenuStrip( PrefsWnd );
  245.         FreeMenus( PrefsMenus );
  246.         PrefsMenus = NULL;    }
  247.  
  248.     if ( PrefsWnd        ) {
  249.         CloseWindow( PrefsWnd );
  250.         PrefsWnd = NULL;
  251.     }
  252.  
  253.     if ( PrefsGList      ) {
  254.         FreeGadgets( PrefsGList );
  255.         PrefsGList = NULL;
  256.     }
  257. }
  258.  
  259.